var request = require('request');
var envConfig = require('./env');
var consoleHelper = require('../org/mime/console');


module.exports = {
  config: null,
  logger: {},
  init: function(env) {
    this.config = envConfig(env);

    consoleHelper.apply(this.logger, [env]);
  },
  request: {
    get: function(p_url, p_callback) {
      request.get(p_url, function(err, response, body) {
        if (kakarotto.config.app.isDev) {
          console.log('');
          console.log('>>>>');
          try {
            console.log('nodejs->request->get url');
            console.log(p_url);
            console.log('nodejs->request->get err');            
            console.log(err);            
            // console.log('nodejs->request->get response headers', typeof response.headers);// object
            console.log('nodejs->request->get response headers');
            console.log(response.headers);
            // console.log('nodejs->request->get response statusCode', typeof response.statusCode);// number
            console.log('nodejs->request->get response statusCode');
            console.log(response.statusCode);
            // console.log('nodejs->request->get response statusMessage', typeof response.statusMessage);// string
            console.log('nodejs->request->get response statusMessage');
            console.log(response.statusMessage);
            // console.log('nodejs->request->get body', typeof body);// string
            console.log('nodejs->request->get body');
            // console.log(JSON.parse(body));
            console.log(body);// 还是直接打印字符串更好；
          } catch (e) {}
          console.log('<<<<');
          console.log('');
        }
        p_callback(err, response, body);
      });
    }
  }
};